<template>
  <div class="song">
    <header>
      <div class="left">单曲</div>

      <div
        class="item"
        @click="$store.commit('addAllSongIntoPlaylist', { list: songs })"
      >
        <img src="@/assets/kugou/播放.png" alt="" />
      </div>
    </header>

    <SearchResultItem v-for="item in songs" :key="item.id" :item="item" />
  </div>
</template>

<script>
import SearchResultItem from "@/components/basics/SearchResultItem.vue";

export default {
  async created() {
    // 获取单曲
    const { keywords } = this;
    const res = await this.axios.get(
      `/cloudsearch?keywords=${keywords}&type=1`
    );

    const { songs } = res.data.result;
    this.songs = songs;
  },
  props: {
    keywords: String,
  },
  data() {
    return {
      songs: [],
    };
  },
  components: {
    SearchResultItem,
  },
};
</script>

<style scoped lang="less">
header {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;

  .item {
    padding: 5px;
    background-color: #ebf5fe;
    border-radius: 10px;
    margin-left: 20px;

    img {
      width: 30px;
      height: 100%;
    }
  }
}
</style>
